package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * 实现翻译服务器
 */
@SuppressWarnings({"all"})
public class UdpDictServer extends UdpEchoServer{

    private HashMap<String, String> dictionary;

    public UdpDictServer(int port) throws SocketException {
        super(port);
        dictionary = new HashMap<>();
        dictionary.put("cat", "猫咪");
        dictionary.put("dog", "小狗");
        dictionary.put("banana", "香蕉");
        dictionary.put("apple", "苹果");
    }

    @Override
    public String process(String request) {
        return dictionary.getOrDefault(request, "暂无收录~");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer udpDictServer = new UdpDictServer(9090);
        udpDictServer.start();
    }
}
